package com.qqbot.impl.exception.handler;

import com.qqbot.impl.exception.BException;
import com.qqbot.impl.exception.code.BaseResponseCode;
import com.qqbot.impl.utils.DataResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * RestExceptionHandler
 *
 * @author changwenpeng
 */
@RestControllerAdvice
@Slf4j
public class RestExceptionHandler {

    /**
     * 操作失败"
     */
    @ExceptionHandler(Exception.class)
    public DataResult handleException(Exception e) {
        log.error("Exception,exception:{}", e, e);
        return DataResult.getResult(BaseResponseCode.OPERATION_ERRO);
    }

    /**
     * 自定义全局异常处理
     */
    @ExceptionHandler(value = BException.class)
    DataResult businessExceptionHandler(BException e) {
        log.error("Exception,exception:{}", e, e);
        return new DataResult(e.getMessageCode(), e.getDetailMessage());
    }

}
